<template>
	<view style="width:100%;">
		<view style="margin-top: 20%">
			<u-row>
				<u-col span="12">
					<view class="center">
						<u-image src="/static/guet.png" width="120rpx" height="120rpx"/>
						<text class="center logo-text">新苗同学</text>
					</view>
				</u-col>
			</u-row>
		</view>
		<view class="login-form">
			<u-input v-model="account" placeholder="用户名"/>
			<u-input v-model="password" placeholder="密码" type="password"/>
			<u-button type="primary" plain @click="login">登录</u-button>
		</view>
	</view>
</template>

<script>
import authApi from "@/api/authApi";

export default {
	data() {
		return {
			account: "",
			password: "",
		};
	},
	methods: {
		login() {
			authApi.doLogin(this.account, this.password).then(_ => {
				uni.switchTab({url: "/pages/index/index"})
			})
		}
	},
	mounted() {
		if (uni.getStorageSync("token") !== null && uni.getStorageSync("token") !== "") {
			uni.switchTab({url: "/pages/index/index"})
		}
	},
}
</script>

<style lang="scss" scoped>
.center {
	display: flex;
	justify-content: center;
	flex-direction: row;
	align-items: center;
}

.logo-text {
	margin-left: 24rpx;
	font-size: 40rpx;
}

.login-form {
	margin-top: 20%;
	margin-left: 120rpx;
	margin-right: 120rpx;
	padding: 36rpx;
	display: flex;
	flex-direction: column;
	gap: 36rpx
}
</style>
